import React, { Component } from 'react';

// 导入封装的方法(首页推荐列表)
import { getGoodList } from '../../api/index.js'

// 导入高阶组件
import { withRouter } from 'react-router-dom'

import '../../styles/Home/Goodlist.css'
class RecommendList extends Component {
    constructor(props) {
        super(props);
        this.state = {
            goodList: [],
        }
    }
    componentDidMount() {
        getGoodList({page:1,count:12}).then((res)=>{
            console.log(res);
            this.setState({goodList:res.data.list})
        })
    }
    goShoplist(index) {
        // console.log(this.props);
        const shopId = this.state.goodList[index].id;
        // console.log(shopId);
        this.props.history.push({pathname:'/product',state:shopId})
    }
    render() {
        return (
            <div className='goodlist'>
                 {
                        this.state.goodList.map((item,index)=>{
                            return (
                                <div className='listbox' key={index} onClick={()=>{this.goShoplist(index)}}>
                                    <img src={item.pic} alt="" />
                                    <span>{item.name}</span>
                                </div>
                            )
                        })
                    }
            </div>
        );
    }
}

export default withRouter(RecommendList);